package com.youpai.platform.vulture.service.gateway.initializer;

import com.youpai.platform.vulture.common.handler.CustomMessageDecoder;
import com.youpai.platform.vulture.common.handler.CustomMessageEncoder;
import com.youpai.platform.vulture.service.handler.netty.NettyChannelDispatchHandler;
import com.youpai.platform.vulture.service.handler.netty.NettyChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @date: 2022/6/23 12:38
 * @author: Anna
 * @version: 1.0
 * @description:
 */
@Component
public class TcpServerChildHandlerInitializer extends ChannelInitializer<SocketChannel> {

    @Resource
    private NettyChannelDispatchHandler nettyChannelDispatchHandler;

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new CustomMessageEncoder())
                .addLast(new CustomMessageDecoder())
                .addLast(new NettyChannelHandler(nettyChannelDispatchHandler));

    }
}
